package com.lc.user.express.my;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lc.user.express.BaseSecondActivity;
import com.lc.user.express.R;
import com.lc.user.express.app.AppContext;
import com.lc.user.express.httpserver.GetApiUser;
import com.lc.user.express.utils.GetToast;
import com.lc.user.express.view.dialog.AffirmDialog;
import com.zcx.helper.http.AsyCallBack;


/**
 * Created by Administrator on 2016/3/23.关于我们
 */
public class AboutUsActivity extends BaseSecondActivity {

    LinearLayout llCheckNewestVersion;//检测版本更新按钮
    String url;//地址
    private TextView tv_version;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_us);
        setTitle("关于我们");
        //初始化相关变量
        initVariable();
    }

    private void initVariable() {
        llCheckNewestVersion = (LinearLayout) findViewById(R.id.llCheckNewestVersion);
        tv_version = (TextView) findViewById(R.id.tv_version);
        tv_version.setText("v" + AppContext.curVersion);
        llCheckNewestVersion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                GetData();
            }
        });
    }

    private void GetData() {
        new GetApiUser(AppContext.curVersion, new AsyCallBack<GetApiUser.Info>() {
            @Override
            public void onSuccess(String toast, int type, final GetApiUser.Info info) throws Exception {
                super.onSuccess(toast, type, info);
                if (info.isNew) {
                    GetToast.useString(cnt, "亲，当前已是最新版本");
                } else {
                    new AffirmDialog(cnt, "检测到新版本，建议您立即更新?", "稍后再说", "立即更新", R.style.MyDialog) {
                        @Override
                        protected void onYesClick() {
                            downBySystem(info.url);
                        }
                    }.show();
                }

            }
        }).execute(cnt);
    }

    private void downBySystem(String url){
        if(!TextUtils.isEmpty(url)){
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            Uri content_url = Uri.parse(url);
            intent.setData(content_url);
            startActivity(intent);
        }
    }

}
